<?php

/*
 *                                                                          
 *       _/_/_/                      _/        _/_/_/_/_/                     
 *    _/          _/_/      _/_/    _/  _/          _/      _/_/      _/_/    
 *   _/  _/_/  _/_/_/_/  _/_/_/_/  _/_/          _/      _/    _/  _/    _/   
 *  _/    _/  _/        _/        _/  _/      _/        _/    _/  _/    _/    
 *   _/_/_/    _/_/_/    _/_/_/  _/    _/  _/_/_/_/_/    _/_/      _/_/       
 *                                                                          
 *
 *  Copyright 2013-2014, Geek Zoo Studio
 *  http://www.ecmobile.cn/license.html
 *
 *  HQ China:
 *    2319 Est.Tower Van Palace 
 *    No.2 Guandongdian South Street 
 *    Beijing , China
 *
 *  U.S. Office:
 *    One Park Place, Elmira College, NY, 14901, USA
 *
 *  QQ Group:   329673575
 *  BBS:        bbs.ecmobile.cn
 *  Fax:        +86-10-6561-5510
 *  Mail:       info@geek-zoo.com
 */
$GLOBALS['db']->getOne("SELECT COUNT(address_id) FROM " . $GLOBALS['ecs']->table('user_address') ." WHERE user_id={$_SESSION['user_id']} ORDER BY address_id DESC") > 9 && abort(28);
($consignee = _POST('consignee')) || abort(19);
($mobile = _POST('mobile')) || abort(20);
$country = _POST('country', 0);
($province = _POST('province')) || abort(22);
($city = _POST('city')) || abort(23);
($district = _POST('district')) || abort(24);
($address = _POST('address')) || abort(25);
$default = (int)_POST('default', 0);
// 身份证号码
$id_card_face = _POST('id_card_face');
// 身份证正反照
$id_card_back = _POST('id_card_back');
$address_arr = [
    'user_id' => $_SESSION['user_id'],
    'consignee' => $consignee,
    'mobile' => $mobile,
    'tel' => $mobile,
    'email' => 'none',
    'country' => $country,
    'province' => $province,
    'city' => $city,
    'district' => $district,
    'address' => $address,
    'default' => $default,
    'id_card_face' => $id_card_face,
    'id_card_back' => $id_card_back
];
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('user_address'), $address_arr, 'INSERT');
($address_id = $GLOBALS['db']->insert_id()) || abort(25);

///
if ($default === 1)
{
	$sql = "UPDATE ".$GLOBALS['ecs']->table('users')." SET address_id={$address_id} WHERE user_id={$_SESSION['user_id']}";
    $GLOBALS['db'] ->query($sql);
}

return [];